#include	<iostream>
using	namespace	std;
char	basecode[256]={},	basepair[4][4]={};
void	make_code(void){
	basecode['a']=basecode['A']=0;
	basecode['c']=basecode['C']=1;
	basecode['g']=basecode['G']=2;
	basecode['t']=basecode['T']=3;
	basecode['u']=basecode['U']=3;
	basepair[0][3]=basepair[3][0]=2;
	basepair[1][2]=basepair[2][1]=3;
	basepair[2][3]=basepair[3][2]=2;
}

float	mfe(string	s){
	size_t	n=s.size();	float	m[n*n]={};
	for(size_t	i=0;	i<n;	i++)	s[i]=basecode[(uint8_t)s[i]];
	for(size_t	i=n-1;	i<n;	i--)	for(size_t	j=i+4;	j<n;	j++){
    	float	z=max(max(m[(i+1)*n+j],m[i*n+j-1]),m[(i+1)*n+j-1]+basepair[(uint8_t)s[i]][(uint8_t)s[j]]);
		for(size_t	k=i+1;	k<j; k++)	z=max(z,m[i*n+k]+m[(k+1)*n+j]);
		m[i*n+j]=z;
	}
    return m[n-1];
}

int	main(void){
	make_code();
	string	s;
	while(getline(cin,s))	cout<<-mfe(s)<<'\n';
	return	0;
}
